﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace PhoneAppProject1
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        void webClientObj_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            //txtXML.Text = e.Result;
            //XElement twitterObj = XElement.Parse(e.Result);
            //var Objv = from Obj in twitterObj.Descendants("status")
            //           select new XMLPaser
            //           { 
            //                ImageURL = Obj.Element("user").Element("profile_image_url").Value,
            //                CreateDate = Obj.Element("text").Value,
            //                Message = Obj.Element("created_at").Value
            //           };

            //LBItemTwitter.ItemsSource = Objv;
           
            //throw new NotImplementedException();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {


            IsolatedStorageSettings iso = IsolatedStorageSettings.ApplicationSettings;
      
            //if (iso.Count == 0)
            //{
                storyLoaded.Begin();
                storyLoaded.Completed += new System.EventHandler(storyLoaded_Completed);
                
        //}
            //else
            //{
            //    iso.Clear();
            //    new System.ComponentModel.CancelEventArgs().Cancel = false;
                
            //}
            ////
			
            //WebClient webClientObj = new WebClient();
            //webClientObj.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClientObj_DownloadStringCompleted);
            //webClientObj.DownloadStringAsync(new Uri("http://rssfeeds.sanook.com/rss/feeds/sanook/hitech.home_electronic.index.xml", UriKind.RelativeOrAbsolute));
        }

        private void btnLogin_Click(object sender, System.Windows.RoutedEventArgs e)
        {
		    
        	// TODO: Add event handler implementation here.
            NavigationService.Navigate(new Uri("/Default.xaml", UriKind.RelativeOrAbsolute));
        }

        private void TextBox_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
			 NavigationService.Navigate(new Uri("/Default.xaml", UriKind.RelativeOrAbsolute));
        	// TODO: Add event handler implementation here.
        }

        private void storyLoaded_Completed(object sender, System.EventArgs e)
        {
			NavigationService.Navigate(new Uri("/Default.xaml", UriKind.RelativeOrAbsolute));
            NavigationService.RemoveBackEntry();
            IsolatedStorageSettings iso = IsolatedStorageSettings.ApplicationSettings;
            iso.Clear();
            iso.Add("Navigate", "true");
            iso.Save();
            
        	// TODO: Add event handler implementation here.
        }

        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }
    }
}